﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace HigLabo.Net.WindowsLive
{
    /// <summary>
    /// 
    /// </summary>
    public class CreateApplicationCommand : WindowsLiveCommand
    {
        /// <summary>
        /// 
        /// </summary>
        public String UserID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Url { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String TermsOfServiceLink { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String PrivacyLink { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public override string GraphApiPath
        {
            get
            {
                if (HttpClient.IsNullOrWhiteSpace(this.UserID))
                    return "me/applications";
                else
                    return this.UserID + "/applications";
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public override HttpMethodName MethodName
        {
            get
            {
                return HttpMethodName.Post;
            }
        }
        /// <summary>
        /// 
        /// </summary>
        public CreateApplicationCommand()
            : this(null)
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="userID"></param>
        public CreateApplicationCommand(String userID)
        {
            this.UserID = userID;
            this.ContentType = "application/json";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override byte[] SetData()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("{");
            sb.AppendFormat("name: \"{0}\"", Name);
            sb.Append(",\r\n");
            sb.AppendFormat("uri: \"{0}\"", Url);
            sb.Append(",\r\n");
            sb.AppendFormat("terms_of_service_link: \"{0}\"", TermsOfServiceLink);
            sb.Append(",\r\n");
            sb.AppendFormat("privacy_link: \"{0}\"", PrivacyLink);
            sb.Append("\r\n}");

            return Encoding.UTF8.GetBytes(sb.ToString());
        }
    }
}
